//package com.autotest.nore.common.utils;
//
//import com.azure.communication.email.EmailClient;
//import com.azure.communication.email.EmailClientBuilder;
//import com.azure.communication.email.models.EmailMessage;
//import com.azure.communication.email.models.EmailSendResult;
//import com.azure.core.util.polling.SyncPoller;
//
//
//public class AzureEmailUtils {
//
//    private AzureEmailUtils() {
//        throw new UnsupportedOperationException("工具类禁止实例化");
//    }
//
//    /**
//     * 同步发送邮件
//     * @param connectionString  Azure 连接字符串（格式：endpoint=https://xxx.communication.azure.com/;accesskey=xxx）
//     * @param senderAddress     发件人地址（需已在 Azure 配置）
//     * @param recipientAddress  收件人地址
//     * @param subject           邮件主题
//     * @param plainTextBody     纯文本正文
//     * @return 是否发送成功
//     */
//    public static boolean sendEmail(
//            String connectionString,
//            String senderAddress,
//            String recipientAddress,
//            String subject,
//            String plainTextBody) {
//        try {
//            // 1. 创建同步客户端
//            EmailClient emailClient = new EmailClientBuilder()
//                    .connectionString(connectionString)
//                    .buildClient();
//
//            // 2. 构建邮件消息
//            EmailMessage emailMessage = new EmailMessage()
//                    .setSenderAddress(senderAddress)
//                    .setToRecipients(recipientAddress)
//                    .setSubject(subject)
//                    .setBodyPlainText(plainTextBody);
//
//            // 3. 同步发送并等待结果
//            SyncPoller<EmailSendResult, EmailSendResult> poller = emailClient.beginSend(emailMessage);
//            poller.waitForCompletion();
//
//            // 4. 返回发送状态
//            return poller.getFinalResult().getStatus() == EmailSendResult.Status.SUCCEEDED;
//        } catch (Exception e) {
//            System.err.println("[AzureEmailUtils] 邮件发送失败: " + e.getMessage());
//            return false;
//        }
//    }
//
//
//    /**
//     * 发送带HTML内容的邮件
//     * @param connectionString  Azure 连接字符串
//     * @param senderAddress     发件人地址
//     * @param recipientAddress  收件人地址
//     * @param subject           邮件主题
//     * @param htmlBody          HTML正文内容
//     * @return 是否发送成功
//     */
//    public static boolean sendHtmlEmail(
//            String connectionString,
//            String senderAddress,
//            String recipientAddress,
//            String subject,
//            String htmlBody) {
//        try {
//            EmailClient emailClient = new EmailClientBuilder()
//                    .connectionString(connectionString)
//                    .buildClient();
//
//            EmailMessage emailMessage = new EmailMessage()
//                    .setSenderAddress(senderAddress)
//                    .setToRecipients(recipientAddress)
//                    .setSubject(subject)
//                    .setBodyHtml(htmlBody);
//
//            SyncPoller<EmailSendResult, EmailSendResult> poller = emailClient.beginSend(emailMessage);
//            poller.waitForCompletion();
//            return poller.getFinalResult().getStatus() == EmailSendResult.Status.SUCCEEDED;
//        } catch (Exception e) {
//            System.err.println("[AzureEmailUtils] HTML邮件发送失败: " + e.getMessage());
//            return false;
//        }
//    }
//
//}
